package com.woniu.controller;

import com.woniu.entity.Reservation;
import com.woniu.service.ReservationService;
import com.woniu.util.ResponseData;
import com.woniu.util.ResponseEnum;
import com.woniu.vo.ReservationVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/reservation")
public class ReservationController {
    @Resource
    private ReservationService reservationService;

    @GetMapping("/list")
    public ResponseData<?> getReservationList(
            @RequestParam(required = false) String keyword,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        List<ReservationVO> reservations = reservationService.getReservationList(keyword, pageNum, pageSize);
        return ResponseData.ok(reservations);
    }

    @PostMapping("/add")
    public ResponseData<?> addReservation(@RequestBody Reservation reservation) {
        boolean success = reservationService.addReservation(reservation);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }

    @DeleteMapping("/{id}")
    public ResponseData<?> deleteReservation(@PathVariable("id") Long id) {
        boolean success = reservationService.deleteReservation(id);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }

    @PostMapping("/update")
    public ResponseData<?> updateReservation(@RequestBody Reservation reservation) {
        boolean success = reservationService.updateReservation(reservation);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }
} 